import 'package:duuchin/components/root_page_head.dart';
import 'package:duuchin/view/sub_pages/singer_page.dart';
import 'package:duuchin/view/sub_pages/song_page.dart';
import 'package:flutter/material.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> with TickerProviderStateMixin {
  int basiceNum = 0;
  TabController _tabController;

  static const List<Tab> _tabs = [
    Tab(text: '推荐'),
    Tab(text: '歌曲'),
    Tab(text: '歌手'),
    Tab(text: '小视频'),
    Tab(text: '听书'),
    Tab(text: '文章'),
    Tab(text: '游戏'),
  ];

  final List<Widget> _tabContent = [
    SongPage(),
    Text('234'),
    SingerPage(),
    Text('122343456'),
    Text('ghfghgfh'),
    Text('5435'),
    Text('hgfds'),
  ];

  @override
  void initState() {
    super.initState();
    // getList();
    _tabController = TabController(
      length: _tabs.length,
      vsync: this,
      initialIndex: basiceNum,
    );
    // 监听切换事件
    _tabController.addListener(() {
      _tabController.index;
    });
  }

  Future getList() async{
    // final result = await Http.get(Api.songInfo);
    // print(result['info']);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: RootPageHead(),
        bottom: TabBar(
          isScrollable: true,
          tabs: _tabs,
          controller: _tabController,
        ),
      ),
      body: TabBarView(
        children: _tabContent,
        controller: _tabController,
      ),
    );
  }
}
